import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { ADD_USER_BIND, BIND_LIST, BIND_PAGE, USAGE_CODE_DETAIL, USAGE_CODE_INFO, USER_BIND_LIST, USER_UN_BIND } from '../api/user-bind';
import { USER_BIND_LIST_ARRAY, USER_BIND_LIST_DATA } from 'src/assets/mock/user-bind';

export interface UsageCodeData{
  name: string,
  address: string,
  bindId: string,
  district: string,
  phone: string,
  region: string,
  relcode: string,
  relname: string,
  type: string,
  usageCode: string,
}

@Injectable({
  providedIn: 'root'
})
export class UserBindService {

  constructor(
    private http: HttpClient
  ) { }

  // 1. 获取当前用户的已绑定列表
  _getUsageCodeInfo(): Observable<any>{
    return this.http.get(USAGE_CODE_INFO);
  }
  _getBindList(): Observable<any>{
    return this.http.get(BIND_LIST);
    // return of(USER_BIND_LIST_ARRAY)
  }
  /**
   * 获取绑定列表 | 费用查缴有用
   * @param pageNumber 
   * @param pageSize 
   * @param meter 
   * @returns 
   */
  _getBindPage(pageNumber: number = 1, pageSize: number = 10, meter: string = 'hide'): Observable<any>{
    return this.http.get(BIND_PAGE, {
      params: new HttpParams({ fromObject: { pageNumber, pageSize, meter } })
    })
  }


  // 添加用户绑定
  _addUserBind(params: any): Observable<any>{
    return this.http.post(ADD_USER_BIND, params)
  }
  _getUserBindList(params: any){
    return this.http.get(USER_BIND_LIST, { params: new HttpParams({ fromObject: params }) })
    // return of(USER_BIND_LIST_DATA)
  }
  _userUnbind(bindId: string): Observable<any>{
    return this.http.post(USER_UN_BIND, {}, {
      params: new HttpParams({ fromObject: { bindId } })
    });
  }

  // 根据用户编号查询用户编号信息
  _getUsageCodeDetail(usageCode: string): Observable<any>{
    return this.http.get(USAGE_CODE_DETAIL + '/' + usageCode)
  }

  // 校验用户编号
  checkUsageCode(usageCode: string, setId: string): Observable<any>{
    const url = `/api/gsxmcp/cf/mg/v1.0/funcData/valid/${setId}/${usageCode}`
    return this.http.get(url)
  }

}
